package com.sit.library.entity.dao;

import com.sit.library.entity.bean.Account;
import com.sit.library.entity.bean.Book;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookMapper {

    @Select("select * from book where Title like #{title}")
    @Results({
            @Result(column = "BookID", property = "id"),
            @Result(column = "Title", property = "title"),
            @Result(column = "Author", property = "author"),
            @Result(column = "Publisher", property = "publisher"),
            @Result(column = "PublishDate", property = "publishDate"),
            @Result(column = "Category", property = "category"),
            @Result(column = "Stock", property = "stock")
    })
    List<Book> findByTitle(String title);

    @Select("select * from book")
    @Results({
            @Result(column = "BookID", property = "id"),
            @Result(column = "Title", property = "title"),
            @Result(column = "Author", property = "author"),
            @Result(column = "Publisher", property = "publisher"),
            @Result(column = "PublishDate", property = "publishDate"),
            @Result(column = "Category", property = "category"),
            @Result(column = "Stock", property = "stock")
    })
    List<Book> findAll();

    @Select("select * from book where BookID=#{id}")
    @Results({
            @Result(column = "BookID", property = "id"),
            @Result(column = "Title", property = "title"),
            @Result(column = "Author", property = "author"),
            @Result(column = "Publisher", property = "publisher"),
            @Result(column = "PublishDate", property = "publishDate"),
            @Result(column = "Category", property = "category"),
            @Result(column = "Stock", property = "stock")
    })
    Book findById(int id);

    @Insert("insert into book (Title, Author, Publisher, PublishDate, Category, Stock) " +
            "values (#{title}, #{author}, #{publisher}, #{publishDate}, #{category}, #{stock})")
    int addBook(Book book);

    @Update("update book set Title=#{title}, Author=#{author}, Publisher=#{publisher}, " +
            "PublishDate=#{publishDate}, Category=#{category}, Stock=#{stock} where BookID=#{id}")
    int updateBook(Book book);

    @Delete("delete from book where BookID=#{bookId}")
    int deleteBook(int bookId);

}
